import tkinter as tk
from tkinter import ttk
import sys
from liquid_cooler_ui import LiquidCoolerUI
from serial_manager import SerialManager
from protocol_parser import ProtocolParser
from data_logger import DataLogger
from config_manager import ConfigManager


class LiquidCoolerController:
    def __init__(self, root):
        self.root = root

        # 初始化组件
        self.serial_manager = SerialManager()
        self.protocol_parser = ProtocolParser()
        self.data_logger = DataLogger()
        self.config_manager = ConfigManager()

        # 创建UI实例
        self.ui = LiquidCoolerUI(
            root,
            self.serial_manager,
            self.protocol_parser,
            self.data_logger,
            self.config_manager
        )


if __name__ == "__main__":
    try:
        root = tk.Tk()
    except tk.TclError as e:
        if 'no display name' in str(e) or 'invalid display name' in str(e):
            print("错误：无法启动图形界面。请检查显示设置。")
            sys.exit(1)
        else:
            raise
    app = LiquidCoolerController(root)
    root.mainloop()